package com.sugar.service.oa.hr.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sugar.common.base.persistence.query.BaseQuery;
import com.sugar.common.base.persistence.query.PageModel;
import com.sugar.domain.oa.hr.EmpAccount;
import com.sugar.persistence.oa.hr.IEmpAccount;
import com.sugar.service.oa.hr.IEmpAccountService;

@Service
public class EmpAccountServiceImpl implements IEmpAccountService {

	@Resource
	private IEmpAccount empAccountDao;

	@Override
	public void deleteEmpAccountService(int id) throws RuntimeException {

		this.empAccountDao.deleteEmpAccountDao(this
				.loadEmpAccountByIdService(id));
	}

	@Override
	public List<EmpAccount> findEmpAccountService(EmpAccount account)
			throws RuntimeException {

		String queryString = "select o from EmpAccount o";

		return this.empAccountDao.findEmpAccountDao(queryString, null, null, null);

	}

	@Override
	public PageModel<EmpAccount> getScorllEmpAccountService(Object[] param,
			int firstPage, int pageSize) throws RuntimeException {

		return this.empAccountDao.getScorllEmpAccountDao(null, null, param,
				firstPage, pageSize, null);
	}

	@Override
	public EmpAccount loadEmpAccountByIdService(int id) throws RuntimeException {

		return this.empAccountDao.loadEmpAccountByIdDao(id);
	}

	@Override
	public void saveEmpAccountService(EmpAccount account)
			throws RuntimeException {
		this.empAccountDao.saveEmpAccountDao(account);
	}

	@Override
	public void updateEmpAccountService(EmpAccount account)
			throws RuntimeException {
		this.empAccountDao.updateEmpAccountDao(account);
	}

	@Override
	public EmpAccount findEmpAccountByParamDao(EmpAccount account) {
		String queryString = "select o from EmpAccount o";

		StringBuffer whereString = new StringBuffer();
		whereString.append("o.username=?").append(BaseQuery.AND).append("o.password=?");

		Object[] param = new Object[] { account.getUsername(), account.getPassword() };
		
		return this.empAccountDao.findEmpAccountByParamDao(queryString, whereString.toString(), param) ;
	}

}
